package org.bridge.db.dao.scheduler;

import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;

import org.bridge.ObjectContainer;
import org.bridge.db.bean.xml.Query;
import org.bridge.db.dao.DAOService;
import org.bridge.db.mapping.DbData;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class LoadPropertiesFromDbJob implements Job {

	ResourceBundle rb = ResourceBundle.getBundle("db");
	
	private static Map globalObjects = new Hashtable();
	
	public void execute(JobExecutionContext context) throws JobExecutionException {
		
		Query query = new Query();
		query.setName("dbData");
		query.setSql("select * from DB_LIST");
		DbData dbData = new DbData();
		dbData.setDbClass(rb.getString("db.class"));
		dbData.setDriver(rb.getString("db.driver"));
		dbData.setUrl(rb.getString("db.url"));
		DAOService dao = new DAOService(dbData);
		Collection c = dao.find(query);
		for (Iterator iter = c.iterator(); iter.hasNext();) {
			DbData data = (DbData) iter.next();
			globalObjects.put(data.getDbName(), data);
		}
	}

	public static Map getGlobalObjects() {
		return globalObjects;
	}

}
